package com.hr.borrowing.service.impl;

import java.util.List;

import com.hr.common.core.domain.model.LoginUser;
import com.hr.common.utils.DateUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.hr.borrowing.mapper.BorrowingMapper;
import com.hr.borrowing.domain.Borrowing;
import com.hr.borrowing.service.IBorrowingService;

import static com.hr.common.utils.SecurityUtils.getLoginUser;

/**
 * 借支权限Service业务层处理
 * 
 * @author guan
 * @date 2024-07-17
 */
@Service
public class BorrowingServiceImpl implements IBorrowingService 
{
    @Autowired
    private BorrowingMapper borrowingMapper;

    /**
     * 查询借支权限
     * 
     * @param userId 借支权限主键
     * @return 借支权限
     */
    @Override
    public Borrowing selectBorrowingByUserId(Long userId)
    {
        return borrowingMapper.selectBorrowingByUserId(userId);
    }

    /**
     * 查询借支权限列表
     * 
     * @param borrowing 借支权限
     * @return 借支权限
     */
    @Override
    public List<Borrowing> selectBorrowingList(Borrowing borrowing)
    {
        return borrowingMapper.selectBorrowingList(borrowing);
    }

    /**
     * 新增借支权限
     * 
     * @param borrowing 借支权限
     * @return 结果
     */
    @Override
    public int insertBorrowing(Borrowing borrowing)
    {
        borrowing.setCreateTime(DateUtils.getNowDate());
        return borrowingMapper.insertBorrowing(borrowing);
    }

    /**
     * 修改借支权限
     * 
     * @param borrowing 借支权限
     * @return 结果
     */
    @Override
    public int updateBorrowing(Borrowing borrowing)
    {
        borrowing.setUpdateTime(DateUtils.getNowDate());
        return borrowingMapper.updateBorrowing(borrowing);
    }

    /**
     * 批量删除借支权限
     * 
     * @param userIds 需要删除的借支权限主键
     * @return 结果
     */
    @Override
    public int deleteBorrowingByUserIds(Long[] userIds)
    {
        return borrowingMapper.deleteBorrowingByUserIds(userIds);
    }

    /**
     * 删除借支权限信息
     * 
     * @param userId 借支权限主键
     * @return 结果
     */
    @Override
    public int deleteBorrowingByUserId(Long userId)
    {
        return borrowingMapper.deleteBorrowingByUserId(userId);
    }

    /**
     * 非管理员查询自身借支权限
     *
     * @param
     * @param userId
     * @return
     */
    @Override
    public Borrowing selectBorrowingById(Long userId) {
        return borrowingMapper.selectBorrowingByUserId(userId);
    }
}
